#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
 
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_freertos_hooks.h"
#include "freertos/semphr.h"
#include "esp_system.h"
#include "driver/gpio.h"

#include "lvgl/lvgl.h"

#include "lvgl/demos/lv_demos.h"

#include "lvgl_helpers.h"
#include "func.h"
void default_bg_color_set(lv_color_t value);
void screen_1(void);
void contanier_init(void);
void screen_2(void);

static lv_obj_t *contanier1= NULL;
static lv_obj_t *contanier2= NULL;

void my_gui(void)
{
    default_bg_color_set(lv_color_hex(0x1e1e1e));
    contanier_init();
    screen_1();
    screen_2();
}


void contanier_init(void)
{
    contanier1= lv_obj_create(lv_scr_act());
    lv_obj_set_size(contanier1,320,240);//设置容器大小
    lv_obj_set_style_radius(contanier1,0,0);//设置容器圆角为直角

    contanier2= lv_obj_create(lv_scr_act());
    lv_obj_set_size(contanier2,320,240);
    lv_obj_set_style_radius(contanier2,0,0);

  lv_obj_clear_flag(contanier1, LV_OBJ_FLAG_HIDDEN);
  lv_obj_add_flag(contanier2, LV_OBJ_FLAG_HIDDEN);

}
void screen_1_cb(lv_event_t * e)
{
    lv_event_code_t code = lv_event_get_code(e);
    printf("code = %d\n", code);
    if (code == LV_EVENT_SHORT_CLICKED)
    {
      lv_obj_add_flag(contanier1, LV_OBJ_FLAG_HIDDEN);
      lv_obj_clear_flag(contanier2, LV_OBJ_FLAG_HIDDEN);
    }
    
}
void screen_1(void)
{
    lv_obj_t *spinner = lv_spinner_create(contanier1,1000,100);
    lv_obj_set_style_arc_color(spinner,lv_color_hex(0xdbd700),LV_PART_MAIN);
    lv_obj_set_style_arc_color(spinner,lv_color_hex(0x0066ff),LV_PART_INDICATOR);
    lv_obj_set_size(spinner, 100, 100);
    lv_obj_set_style_arc_width(spinner,10,LV_PART_MAIN);
    lv_obj_set_style_arc_width(spinner,10,LV_PART_INDICATOR);

    lv_obj_t *btn = lv_btn_create(contanier1);
    lv_obj_set_size(btn, scr_act_width() / 3, scr_act_height() / 7);
    lv_obj_center(btn);
    lv_obj_add_event_cb(btn,screen_1_cb,LV_EVENT_SHORT_CLICKED,NULL);

    lv_obj_t *label = lv_label_create(btn);
    lv_label_set_text_fmt(label,"screen_1");

}

void screen_2_cb(lv_event_t * e)
{
    lv_event_code_t code = lv_event_get_code(e);
    printf("code = %d\n", code);
    if (code == LV_EVENT_SHORT_CLICKED)
    {
      lv_obj_clear_flag(contanier1, LV_OBJ_FLAG_HIDDEN);
      lv_obj_add_flag(contanier2, LV_OBJ_FLAG_HIDDEN);
    }
    
}

void screen_2(void)
{

    lv_obj_t *btn = lv_btn_create(contanier2);
    lv_obj_set_size(btn, scr_act_width() / 3, scr_act_height() / 7);
    lv_obj_center(btn);
    lv_obj_add_event_cb(btn,screen_2_cb,LV_EVENT_SHORT_CLICKED,NULL);

    lv_obj_t *label = lv_label_create(btn);
    lv_label_set_text_fmt(label,"screen_2");

}
void default_bg_color_set(lv_color_t value)
{
    lv_obj_set_style_bg_color(lv_scr_act(),value,LV_STATE_DEFAULT);
}